<template>
  <div>
    <!-- 我创建的电台 -->
    <div
      class="u-title"
      v-show="radionum!==0"
    >{{nkname}}创建的电台({{radionum}})</div>
    <ul
      class="m-cvrlst2"
      v-show="radionum!==0"
    >
      <li
        v-for="(item,index) in radioList"
        :key="index"
        class="radiodetail"
      >
        <a href="#">
          <img v-lazy="item.picUrl">
        </a>
        <div class="kong">
          <a href="#">{{item.name}}</a>
          <div class="share">
            <span
              class="iconfont icon-fenxiang2"
              @click="dialogFormVisible = true"
            ></span>
          </div>
        </div>
        <div class="read">订阅{{item.subCount}}次</div>
        <div class="banben">{{item.programCount}}期</div>
      </li>
    </ul>
    <!-- 我创建的歌单 -->
    <div
      class="u-title"
      v-show="jienum!==0"
    >{{nkname}}创建的歌单({{jienum}})</div>
    <ul
      class="m-cvrlst"
      v-show="jienum!==0"
    >
      <li
        v-for="(item,index) in userplaylist.slice(0, jienum)"
        :key="index"
        @click="gopldetail(item.id)"
      >
        <div class="u-cover">
          <a href="#">
            <img v-lazy="item.coverImgUrl">
          </a>
          <div class="bottom">
            <i class="iconfont icon-bofang"></i>
            <i class="iconfont icon-erjiyuyin"></i>
            <span>{{item.playCount}}</span>
          </div>
        </div>
        <p
          class="dec"
          :title="item.name"
        >
          {{item.name}}
        </p>
      </li>
    </ul>
    <!-- 我收藏的歌单 -->
    <div
      class="u-title"
      v-show="userplaylist.length - jienum!==0"
    >{{nkname}}收藏的歌单({{userplaylist.length - jienum}})</div>
    <ul
      class="m-cvrlst"
      v-show="userplaylist.length - jienum!==0"
    >
      <li
        v-for="(item,index) in userplaylist.slice(jienum)"
        :key="index"
        @click="gopldetail(item.id)"
      >
        <div class="u-cover">
          <a href="#">
            <img v-lazy="item.coverImgUrl">
          </a>
          <div class="bottom">
            <i class="iconfont icon-bofang"></i>
            <i class="iconfont icon-erjiyuyin"></i>
            <span>{{item.playCount/10000}}万</span>
          </div>
        </div>
        <p
          class="dec"
          :title="item.name"
        >{{item.name}}</p>
      </li>
    </ul>
    <!-- 分享弹窗 -->
    <el-dialog
      title="分享"
      :visible.sync="dialogFormVisible"
      :modal="false"
      :lock-scroll="false"
    >
      <el-tabs
        type="border-card"
        @tab-click="showIcon"
      >
        <el-tab-pane label="分享给大家">
          <div class="u-txtwrap">
            <textarea
              cols="30"
              rows="10"
              class="u-txt"
              placeholder="说点什么吧"
            ></textarea>
            <div class="info">
              <p>电台：{{radioList[0].name}}&nbsp;by&nbsp;{{nkname}}</p>
            </div>
          </div>
          <div class="oper">
            <div class="face">
              <i class="iconfont icon-lianxiaolianmanyi-"></i>
              <i class="iconfont icon-aite1"></i>
              <i class="iconfont icon-tupian"></i>
            </div>
            <span class="zinum">140</span>
          </div>
        </el-tab-pane>
        <el-tab-pane
          label="私信分享"
          class="sectab"
        >
          <div class="u-err">最多选择10位好友</div>
          <div class="j-flag">
            <div class="txtpa">
              <input
                type="text"
                class="txt"
                placeholder="选择或输入好友昵称"
              >
            </div>
            <div class="u-txtwrap">
              <textarea
                cols="30"
                rows="10"
                class="u-txt"
                placeholder="说点什么吧"
              ></textarea>
              <div class="info">
                <p>电台：许嵩电台&nbsp;by&nbsp;许嵩</p>
              </div>

            </div>
            <div class="oper">
              <div class="face">
                <i class="iconfont icon-lianxiaolianmanyi-"></i>
              </div>
              <span class="zinum">140</span>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="dialogFormVisible = false"
        >分享</el-button>
        <div
          class="sharego"
          v-show="showShIcon"
        >
          <span>同时分享到：</span>
          <ul>
            <li>
              <a
                href="#"
                title="新浪微博"
                class="iconfont icon-weibo2"
              ></a>
            </li>
            <li>
              <a
                href="#"
                title="豆瓣网"
                class="iconfont icon-douban1"
              ></a>
            </li>
          </ul>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data () {
    return {
      userId: 0,
      // 用户歌单
      userplaylist: [],
      // 分开收藏歌单与我的歌单的界限
      jienum: 2,
      radionum: 0,
      radioList: [{ name: '' }],
      showShIcon: true,
      dialogFormVisible: false,
    }
  },
  props: ['nkname'],
  created () {
    this.getuserList()
    this.getradioList()
  },
  watch: {
    // 监听到id变化
    userId (newVal, oldVal) {
      console.log('触发了监听器：', newVal, oldVal)
      this.getuserList()
      this.getradioList()
      // this.$router.go(0);  一直再刷新
    }
  },
  methods: {
    showIcon (tab, event) {
      console.log(tab)
      if (tab.index === '0') {
        this.showShIcon = true
      }
      else {
        this.showShIcon = false
      }
    },
    // 获取用户歌单
    async getuserList () {
      this.userId = this.$route.query.id
      // console.log('到了home页，id：', this.userId)
      let res = await axios.get('https://autumnfish.cn//user/playlist?uid=' + this.userId)
      this.userplaylist = res.data.playlist
      for (let j = 0; j < this.userplaylist.length; j++) {
        if (this.userplaylist[j].creator.userId == this.userId) {
          this.jienum = j + 1;
        }
      }
      // console.log(res)
    },
    // 获取用户电台
    async getradioList () {
      // let res = await axios.get('https://autumnfish.cn//user/dj?uid=' + this.userId)
      // this.radioList = res.data.programs
      let res = await axios.get('https://autumnfish.cn//user/audio?uid=' + this.userId)
      this.radioList = res.data.djRadios
      // console.log('电台')
      // console.log(res)
      this.radionum = res.data.count
    },
    // 点击歌单页面，进入详情
    gopldetail (ids) {
      this.$router.push({ path: '/playlist', query: { id: ids } })
      // console.log('在用户页点击了歌单页面，进入详情页，歌单的id：', ids)
    }
  }
}
</script>

<style lang="less" scoped>
a {
  text-decoration: none;
}
p {
  padding: 0;
  margin: 0;
}
.u-txtwrap {
  border: 1px solid #d9d9d9;
  border-radius: 2px;
  padding-right: 14px;
  .u-txt {
    resize: none;
    overflow: auto;
    height: 106px;
    border: none;
    width: 100%;
    margin: 0;
    margin-right: -20px;
    padding: 5px 6px 6px;
    border-radius: 2px;
    line-height: 19px;
    box-sizing: content-box;
  }
  .info {
    height: 45px;
    line-height: 45px;
    margin: 0 -14px 0 0;
    padding: 0 10px;
    cursor: auto;
    background-color: transparent !important;
    border-top: 1px solid #e5e5e5;
    font-size: 14px;
    p {
      margin-right: 15px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      word-wrap: normal;
    }
  }
}
.oper {
  height: 20px;
  margin-top: 10px;
  .face {
    float: left;
    .iconfont {
      cursor: pointer;
      margin-right: 10px;
      font-size: 20px;
      color: #666;
    }
  }
  .zinum {
    float: right;
    color: #999;
    font-size: 12px;
  }
}
.dialog-footer {
  .sharego {
    line-height: 22px;
    float: left;
    display: flex;
    justify-content: left;
    align-items: center;
    span {
      color: #666;
      font-size: 15px;
    }
    ul {
      display: flex;
      justify-content: left;
      align-items: center;
      margin: 0;
      padding: 0;
      li {
        list-style: none;
        margin-left: 8px;
        height: 22px;
        a {
          font-size: 23px;
          color: #999;
        }
      }
    }
  }
}
.sectab {
  .u-err {
    display: none;
    height: 17px;
    margin-top: 5px;
    line-height: 17px;
    color: #e33232;
    font-size: 12px;
  }
  .j-flag {
    .txtpa {
      border: 1px solid #d9d9d9;
      border-radius: 2px;
      padding-right: 14px;
      margin-bottom: 10px;
      cursor: text;
      .txt {
        border: none;
        padding: 10px 0 10px 10px;
      }
    }

    .u-txtwrap {
      .u-txt {
        height: 60px;
      }
    }
  }
}

// 创建的歌单
.u-title {
  border-bottom: 2px solid #c20c0c;
  height: 33px;
  font-size: 20px;
  line-height: 28px;
}
.m-cvrlst {
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  margin: 20px 0 0 -50px;
  li {
    list-style: none;
    width: 140px;
    padding: 0 0 30px 50px;
    line-height: 1.4;
    height: 165px;
    overflow: hidden;
    .u-cover {
      width: 140px;
      height: 140px;
      position: relative;
      a {
        display: inline-block;
        width: 140px;
        height: 140px;
        text-decoration: none;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .bottom {
        position: absolute;
        left: 0;
        bottom: 0;
        width: 100%;
        height: 27px;
        background-color: rgba(0, 0, 0, 0.5);
        color: #ccc;
        font-size: 12px;
        .icon-erjiyuyin {
          position: absolute;
          left: 10px;
          bottom: 5px;
          width: 16px;
          height: 17px;
          margin-right: 5px;
        }
        span {
          position: absolute;
          left: 32px;
          bottom: 5px;
          // width: 16px;
          height: 15px;
        }
        .icon-bofang {
          position: absolute;
          right: 10px;
          bottom: 5px;
          width: 16px;
          height: 17px;
        }
      }
    }
    .dec {
      margin: 0;
      padding: 0;
      margin: 8px 0 3px;
      font-size: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      word-wrap: normal;
      cursor: pointer;
    }
    .dec:hover {
      text-decoration: underline;
    }
  }
}
.m-cvrlst2 {
  margin: 0;
  padding: 0;
  margin-bottom: 24px;
  border: 1px solid #e5e5e5;
  border-top: none;
  .radiodetail {
    height: 50px;
    padding: 10px 0;
    line-height: 50px;
    display: flex;
    justify-content: left;
    align-items: center;
    a {
      display: block;
      width: 50px;
      height: 50px;
      margin-left: 20px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .kong {
      width: 500px;
      padding-right: 38px;
      margin-left: 10px;
      position: relative;
      a {
        font-size: 12px;
        color: #333;
        display: block;
        width: 60%;
        height: 50px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        word-wrap: normal;
      }
      .share {
        position: absolute;
        top: 16%;
        right: 0;
        margin-top: -6px;
        visibility: hidden;
        .iconfont {
          margin-right: 10px;
          text-indent: -9999px;
          cursor: pointer;
          font-size: 15px;
          width: 16px;
          height: 14px;
          color: #949393;
        }
      }
    }
    .read {
      width: 216px;
      margin-left: 10px;
      color: #666;
      font-size: 12px;
      text-align: center;
    }
    .banben {
      width: 44px;
      margin-left: 10px;
      color: #999;
      font-size: 12px;
    }
  }
  .radiodetail:hover {
    background-color: #eeeeee;
    .share {
      visibility: visible;
    }
    .share:hover {
      color: #666;
    }
  }
}
</style>
